<template>
  <div style="width: 100%;height: 100%;display: flex">
    <div class="left_box">
      <div class="code_box">
        <ace-editor style="width: 100%;height: 100%" :html-text-value="htmlStr" :ts-text-value="tsStr"></ace-editor>
      </div>
    </div>
    <div id="load4490_box">
      <div class="popup_box">
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import {initMap} from "@/widgets/modelExample_cesium/common/initMap";
import {nextTick, onMounted, ref} from "vue";
import {
  loadModelLayer,
  craeteDynamicShadeWallGraphics
} from "../../common/loadLayers";
import gisTools from "../../common/GisTools";
import AceEditor from "@/components/aceEditor.vue";

const htmlStr = ref(`
   <template>
  <div style="width: 100%;height: 100%;display: flex">
    <div id="load4490_box">
      <div class="popup_box">
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import {initMap} from "@/widgets/modelExample_cesium/common/initMap";
import {nextTick, onMounted, ref} from "vue";
import {
  loadModelLayer,
  craeteDynamicShadeWallGraphics
} from "../../common/loadLayers";
import gisTools from "../../common/GisTools";


const renderStart = () => {
  loadModelLayer(
      cViewer.value,
      '/public/otherModal/cityHouse/tileset.json',
      "md2_tiles",
      {
        spaceError:1,
        bLocTo: false,
        height: 0,
        offset: {
          "tx": 119.558036337955121,
          "ty": 31.795970233324241,
          "tz": 0,
          "rx": 0,
          "ry": 0,
          "rz": 0
        }
      }
  );
  gisTools.cameraFlyToPoint(cViewer.value,[119.559036337955121,  31.755970233324241],3000);
  craeteDynamicShadeWallGraphics(cViewer.value,{
    positions: [
      119.559036337955121,
      31.755970233324241,
      200,
      119.559886022728548,
      31.752113971660176,
      200,
      119.55988602228548,
      31.752113971660176,
      200,
      119.564700903111373,
      31.752702214964863,
      200,
      119.568361083673878,
      31.752310052761739,
      200,
      119.569711864595746,
      31.757059572777369,
      200,
      119.565768455775441,
      31.757124933144556,
      200,
      119.559036337955121,
      31.755970233324241,
      200
    ]
  })
}
const cViewer = ref();
onMounted(() => {
  cViewer.value = initMap("load4490_box")
  nextTick(()=>{
    renderStart();
  })
})
<\/script>

<style lang="scss" scoped>
#load4490_box {
  width: 60%;
  height: 100%;
}

.popup_box {
  position: fixed;
  left: calc(40% + 40px);
  min-width: 100px;
  width: auto;
  top: 80px;
  height: 60px;
  z-index: 10;
}
</style>

`);

const tsStr = ref(`

/**
 *  动态渐变墙
 * @param {object} options
 * @param {Array<any>>} options.positions - 坐标数组
 * @param {number} options.alp - 透明比例 0~1
 * @param {number} options.num - 渐变步长
 * @param {number} options.speed - 速度 0~1
 * @param {object} options.color - 颜色
 * @param {string} options.image - 材质图片
 */
const craeteDynamicShadeWallGraphics=(viewer:any,options:any)=> {
    let defaultOption:any={
        alp:1,
        num:20,
        color:Cesium.Color.RED,
        speed:0.03,
        image:"texturex/fence.png"
    };
    Object.assign(defaultOption,options)
    let { positions ,alp,num, color,speed,image } =defaultOption;
    if(!positions || positions.length===0){ return  } ;
    positions= Cesium.Cartesian3.fromDegreesArrayHeights(positions)
    let wallEntity:any=new Cesium.Entity();
        wallEntity.wall = {
            positions:positions,
            material: new Cesium.ImageMaterialProperty({
                image: getAssetsFile(image),
                transparent: true,
                color: new Cesium.CallbackProperty(function () {
                    if (num % 2 === 0) {
                        alp -= speed;
                    } else {
                        alp += speed;
                    }
                    if (alp <= 0.1) {
                        num++;
                    } else if (alp >= 1) {
                        num++;
                    }
                    return color.withAlpha(alp);
                }, false),
            }),
        };
        return   viewer.entities.add(wallEntity);

}

 export {
    craeteDynamicShadeWallGraphics
 }
`);

const renderStart = () => {
  loadModelLayer(
      cViewer.value,
      '/public/otherModal/cityHouse/tileset.json',
      "md2_tiles",
      {
        spaceError:1,
        bLocTo: false,
        height: 0,
        offset: {
          "tx": 119.558036337955121,
          "ty": 31.795970233324241,
          "tz": 0,
          "rx": 0,
          "ry": 0,
          "rz": 0
        }
      }
  );
  gisTools.cameraFlyToPoint(cViewer.value,[119.559036337955121,  31.755970233324241],3000);
  craeteDynamicShadeWallGraphics(cViewer.value,{
    positions: [
      119.559036337955121,
      31.755970233324241,
      200,
      119.559886022728548,
      31.752113971660176,
      200,
      119.55988602228548,
      31.752113971660176,
      200,
      119.564700903111373,
      31.752702214964863,
      200,
      119.568361083673878,
      31.752310052761739,
      200,
      119.569711864595746,
      31.757059572777369,
      200,
      119.565768455775441,
      31.757124933144556,
      200,
      119.559036337955121,
      31.755970233324241,
      200
    ]
  })
}
const cViewer = ref();
onMounted(() => {
  cViewer.value = initMap("load4490_box")
  nextTick(()=>{
    renderStart();
  })
})
</script>

<style lang="scss" scoped>
.left_box {
  width: 40%;
  height: 100%;
  display: flex;
  flex-direction: row-reverse;

  .code_box {
    margin: 10px;
    width: calc(100% - 220px);
    height: calc(100% - 20px);
    background-color: #ffffff;
    color: #000;
    overflow-x: hidden;
    overflow-y: auto;
  }
}

#load4490_box {
  width: 60%;
  height: 100%;
}

.popup_box {
  position: fixed;
  left: calc(40% + 40px);
  min-width: 100px;
  width: auto;
  top: 80px;
  height: 60px;
  z-index: 10;
}
</style>
